package com.shiliuzi.www.common;

import lombok.Data;

@Data
public class R {
    private Integer status;
    private String msg;
    private Object data;

    public R() {
    }

    public R(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public R(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    // 成功不带数据
    public static R success(){
        return new R(200,"成功");
    }

    // 成功带数据
    public static R success(Object data){
        return new R(200, "成功", data);
    }

    public static R success(Integer status, String msg, Object data){
        return new R(status, msg, data);
    }

    // 错误
    public static R error(String msg){
        return new R(400,msg);
    }

    public static R error(Integer status, String msg){
        return new R(status,msg);
    }

    public static R operation(boolean flag, Object data, String msg){
        if (flag){
            return new R(200, "成功", data);
        }else {
            return new R(400, msg);
        }
    }
}
